package org.ykh.gmall.product.controller;

import org.ykh.gmall.product.BaseSaleAttr;
import org.ykh.gmall.product.SpuInfo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.ykh.gmall.product.service.ManagerService;
import org.ykh.gmall.result.Result;

import java.util.List;

@RestController
@RequestMapping("/admin/product")
public class SpuManagerController {

    @Autowired
    private ManagerService managerService;



    /**
     * 保存spuInfo
     * /admin/product/saveSpuInfo
     * @return
     */
    @PostMapping("/saveSpuInfo")
    public Result saveSpuInfo(@RequestBody SpuInfo spuInfo){

        managerService.saveSpuInfo(spuInfo);

        return Result.ok();
    }

    /**
     * 获取销售属性集合
     * admin/product/baseSaleAttrList
     * @return
     */
    @GetMapping("/baseSaleAttrList")
    public Result baseSaleAttrList(){
        List<BaseSaleAttr> baseSaleAttrList=managerService.baseSaleAttrList();

        return Result.ok(baseSaleAttrList);
    }
    /**
     * spuInfo分页列表
     * /admin/product/{page}/{limit}
     * @param page
     * @param limit
     * @param spuInfo
     * @return
     */
    @GetMapping("/{page}/{limit}")
    public Result findSpuListByPage(@PathVariable Long page,
                                    @PathVariable Long limit,
                                     SpuInfo spuInfo ){

        //封装page对象
        Page<SpuInfo> spuInfoPage=new Page<>(page,limit);
        //调用service
      IPage<SpuInfo> spuInfoIPage= managerService.findSpuListByPage(spuInfoPage,spuInfo);


        return Result.ok(spuInfoIPage);
    }
}
